﻿using MediatR;
using Production_Set.API.Application.Commands.Customerser;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.Produce.Customers;
using THE_WIND_RISES.Common.Domans.Produce.Order;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Set.API.Application.Commands.Orderers
{
    /// <summary>
    /// 订单行删除
    /// </summary>
    public class OrderLineDelHanbdler : IRequestHandler<OrderLineDelCommend, Result>
    {
        private readonly IBaseRepository<OrderLine> OrderLine;

        public OrderLineDelHanbdler(IBaseRepository<OrderLine> OrderLine)
        {
            this.OrderLine = OrderLine;
        }

        public async Task<Result> Handle(OrderLineDelCommend request, CancellationToken cancellationToken)
        {
            var results = new Result() { Code = (int)CommonErrorCodes.Delete };

            string sql = "UPDATE OrderLine SET IsDelete=1 WHERE OrderLineId=" + request.OrderLineId;
            var list = OrderLine.Update(sql, results);
            if (list != null)
            {
                results.Code = (int)CommonErrorCodes.Success;
                results.Msg = "删除成功";
            }

            return results;
        }
    }
}
